<?php 

function checklog(){
	if(!isset($_SESSION['uid'])){
		//var_dump('111');exit;
		header('Location:http://localhost/project/fly/index.php/home/login/index');
	}
}

function Ctime($time=null)
{
	if($time==null){
		return date("Y-m-d H:i:s");
	}
	
	$diff = time()-$time;

	if($diff<60){
		return "刚刚";
	}elseif($diff<3600){
		return ceil(($diff/60))."分钟前";
	}elseif($diff<86400){
		return ceil(($diff/3600))."小时前";
	}elseif($diff<(86400*7)){
		return ceil(($diff/86400))."天前";
	}else{
		return date("Y-m-d H:i:s",$time);
	}
}

function xbsmail($email,$title,$content){

	Vendor('PHPMailer.PHPMailerAutoload');

	$mail = new PHPMailer;

	//$mail->SMTPDebug = 3;                               // Enable verbose debug output

	$mail->isSMTP();                                      // Set mailer to use SMTP
	$mail->Host = 'smtp.qq.com';  // Specify main and backup SMTP servers
	$mail->SMTPAuth = true;                               // Enable SMTP authentication
	$mail->Username = '375138891@qq.com';                 // SMTP username
	$mail->Password = 'ttiuaiyvuxuabjej';                           // SMTP password
	$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
	$mail->Port = 465;                                    // TCP port to connect to

	$mail->setFrom('375138891@qq.com', '老司机论坛');
	$mail->addAddress($email);     // Add a recipient
	//$mail->addAddress('ellen@example.com');               // Name is optional
	//$mail->addReplyTo('info@example.com', 'Information');
	//$mail->addCC('cc@example.com');
	//$mail->addBCC('bcc@example.com');

	//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
	//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
	$mail->isHTML(true);                                  // Set email format to HTML

	$mail->Subject = $title;
	$mail->Body    = $content;
	/*$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';*/

	if(!$mail->send()) {
	    echo 'Message could not be sent.';
	    echo 'Mailer Error: ' . $mail->ErrorInfo;
	} else {
	    echo 'Message has been sent';
	}
}

 ?>